#include "Exp2.h"

void Exp2()
  {
    cleardevice();
    int Still = 1;
    Object Cursor, *pCursor = &Cursor;
    InitExp2Cursor(pCursor);

    char Map[350], *pMap = Map;
    ReadMapN(pMap, 2);

    OptIntro(2);

    while (Still)
      {
        OptMap2();
        OptCursor(pCursor);
        if (pCursor->Treasure == 'K')//not get key yet
          OptDoorLight(907, 550);
        if (Reached(pCursor) == 1)//reach door
            if (pCursor->Treasure != 'K')
            OptKey(665, 10);
        GetExp2Key(pCursor);

        PlayerAct(pCursor, pMap, &Still);
        Exp2Solved(pCursor, &Still);
        FlushBatchDraw();
      }
    OptMenuBk();
  }
void InitExp2Cursor(Object *pCursor)
  {
    pCursor->HP = 10;
    pCursor->X = 15, pCursor->Y = 10;
    pCursor->GridX = 0, pCursor->GridY = 0;
    pCursor->Treasure = 'N';
  }

int Reached(Object *pCursor)
  {
    int static ReachTime = 0;
    if (ReachExp2Door(pCursor))
      ReachTime++;
    if (ReachTime == 2)
      ReachTime = 0;
    return ReachTime;
  }
int ReachExp2Door(Object *pCursor)
  {
    int GridX = pCursor->GridX, GridY = pCursor->GridY;
    if ((GridX == 18)||(GridX == 19))
       if ((GridY == 11)||(GridY == 12))
            return 1;
    return 0;
  }
void GetExp2Key(Object *pCursor)
  {
    int GridX = pCursor->GridX, GridY = pCursor->GridY;
    if (GridX == 13)
      if (GridY == 0)
        pCursor->Treasure = 'K';
  }
void Exp2Solved(Object *pCursor, int *Still)
  {
    if (pCursor->Treasure == 'K')
      if (ReachExp2Door(pCursor))
        {
          *Still = 0;
          Accomplish('2');
        }
  }

void OptMap2()
  {
    IMAGE ImgMap2;
    loadimage(&ImgMap2, _T("Pic/Exp2/Map2.png"));
    putimage(0, 0, &ImgMap2);
  }
